{extend name='layout:app'}

{block name='css'}
<link rel="stylesheet" href="__STATIC__/css/datePicker.css">
<script src="__STATIC__/js/iscroll.js"></script>
<script src="__STATIC__/js/datePicker.js"></script>
<link rel="stylesheet" href="__STATIC__/css/onsite-service.css">
{/block}

{block name='content'}
<div id="app">
    <div class="nav">
        <i class="el-icon-arrow-left icon_left" @click="back"></i>
        <div>上门服务</div>
        <i class="iconfont icon-home icon_right" @click="home"></i>
    </div>
    <div class="top-banner">
        <div class="font-cont">送货上门</div>
        <img src="__STATIC__/imgs/item-icon_004.png" alt="">
    </div>
    <div class="yizhan-info">
        <div class="info-item" @click="chooseReceiver">
            <div class="name">
                <span>收件人信息</span>
                <i class="el-icon-arrow-right"></i>
            </div>
            <div class="active-info" id="receiverInfo"><!--吴某某   15885220135   成都市青羊区宽窄巷子9号--></div>
        </div>
        <!--<div class="info-item">
            <div class="name">
                <span>送货上门时间</span>
                <i class="el-icon-arrow-right"></i>
            </div>
            <el-input v-model="datetime" placeholder="请选择时间" class="active-info" id="choosedate"></el-input>
        </div>-->
    </div>

    <div class="info-tips">*上门收件一公斤内收取服务费1元，超过1公斤，和服务人员协商处理</div>

    <div class="btn-area">
        <div class="order">
            <el-button type="primary" @click="btnOrder">下单</el-button>
        </div>
    </div>
</div>
{/block}

{block name='footer'}{/block}
{block name='js'}
<script>
    var that;
    new Vue({
        el:'#app',
        data: {
            // datetime: '',
            addrList: false,
            id: ''
        },
        created() {
            that = this
            /*var _sendInfo = JSON.parse(localStorage.getItem('_SendAddr'))
            if(_sendInfo) {
                $('#receiverInfo').html(`${_sendInfo.name} ${_sendInfo.phone} ${_sendInfo.addr}`)
                this.addrList = _sendInfo
            }*/
            $.get('/index/person/getaddr?type=1',function (res) {
                if(res.code === 0) {
                    for(item of res.data) {
                        if(item.addr_default === 1) {
                            $('#receiverInfo').html(`${item.addr_name} ${item.addr_phone} ${item.addr_province} ${item.addr_city} ${item.addr_area} ${item.addr_detail}`)
                        }
                    }
                    if(res.data.length) {
                        that.addrList = true
                    }
                }
            })

            const code = location.href.split('code=')[1]
            if(code) {
                this.id= code
            }

        },
        methods: {
            back() {
                window.history.go(-1)
            },
            home() {
                location.href = '/'
            },
            chooseReceiver() {
                sessionStorage.setItem('clickType', 1)
                sessionStorage.setItem('service', 'onsite')
                if(!this.addrList) {
                    location.href = '/index/person/addNewAddr'
                    return
                }
                location.href = '/index/person/address.html'
            },
            btnOrder() {
                if(!$('#receiverInfo').html()) {
                    alert('请完善信息！')
                    return
                }
                if(!this.id.length) {
                    location.href = '/index/person/mycode'
                    return
                }
                $.post('/index/sender/saveSendOrder',{
                        receiver_info:$('#receiverInfo').html(),
                        code: that.id
                    },
                    function (res) {
                        console.log(res)
                        if(res.code === 0) {
                            that.$message({
                                message: '下单成功!',
                                type: 'success',
                                duration: 2000
                            });
                            setTimeout(() => {
                                location.href = '/index/person/mysender'
                            }, 2000)
                        }
                },'json')
            }
        }
    });

</script>
{/block}